<template>
  <!--封装better-scroll  -->
  <div ref="wrapper">
      <slot></slot>
    </div>
</template>

<script>
  import BScroll from 'better-scroll'
  export default {
    name: "scroll",
    props: {
      probeType: { // 探针
        type: Number,
        default: 1
      },
      click: {
        type: Boolean,
        default: true
      },
      data: { // 加载的数据
        type: Array,
        default: null
      }
    },
    mounted() {
      setTimeout(() => {
        this._initScroll()
      }, 20)
    },
    methods: {
      _initScroll(){
        if(!this.$refs.wrapper){
          return
        }
        this.scroll = new BScroll(this.$refs.wrapper, {
          probeType: this.probeType,
          click: this.click
        })
      },
      enable(){
        this.scroll && this.scroll.enable()
      },
      disable(){
        this.scroll && this.scroll.disable()
      },
      refresh(){
        this.scroll && this.scroll.refresh()
      }
    },
    watch: {
      data() { // 监听数据变化，进行刷新操作
        setTimeout(() => {
          this.refresh()
        }, 20)
      }
    },

  }
</script>

<style scoped>

</style>
